package com.fruit.service.rights.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fruit.mapper.maintenance.BaseOperationRecordMapper;
import com.fruit.service.rights.BaseOperationsManager;
import com.fruit.util.ResultInfo;
import com.fruit.util.ResultUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 基地维护记录Service
 * 
 * @author Administrator
 * @version 2017.12.29 11:40
 */
@Slf4j
@Service("baseOperationsService")
public class BaseOperationsService implements BaseOperationsManager {
	@Autowired
	private BaseOperationRecordMapper baseOperationRecordMapper;
	@Override
	public Map<String, Object> getRecords(String tradeId, Map<String, Object> params) {
		log.info("【" + tradeId + "】---【基地维护记录】---【开始】---");
		Map<String, Object> result = new HashMap<String, Object>();
		if (params == null) {
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "param_error", "传入参数不能为null!"));
			return result;
		}
		log.info("【" + tradeId + "】---【基地维护记录】---【params】---{}", params.toString());
		if (null == params.get("areaGoodsCountId") || "".equals(params.get("areaGoodsCountId"))) {
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "param_error", "传入参数区域统计商品id不能为空!"));
			return result;
		}
		if (null == params.get("startTime") || "".equals(params.get("startTime"))) {
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "param_error", "传入参数期次开始时间不能为空!"));
			return result;
		}
		if (null == params.get("endTime") || "".equals(params.get("endTime"))) {
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "param_error", "传入参数期次结束时间不能为空!"));
			return result;
		}
		if (null == params.get("startNum") || "".equals(params.get("startNum"))) {
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "param_error", "传入参起始条数不能为空!"));
			return result;
		}
		if (null == params.get("pageNum") || "".equals(params.get("pageNum"))) {
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "param_error", "传入参数显示条数不能为空!"));
			return result;
		}
		if (null == params.get("sortFlag") || "".equals(params.get("sortFlag"))) {
			params.put("sortFlag", "DESC"); //降序
		}
		try {
			List<Map<String, Object>> records = baseOperationRecordMapper.getRecords(params);
			result.put("dataList", records);
			result.put("result", ResultUtil.initResult(ResultInfo.SUCCESS, "ok", ""));
		} catch (Exception e) {
			log.error("【" + tradeId + "】---【基地维护记录】---【异常】---{}", e);
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "exception", "系统异常"));
		}
		log.info("【" + tradeId + "】---【基地维护记录】---【结束】---");
		return result;
	}

}
